
function preUpdate(obj) {
	$(obj).hide();
	$(obj).next("input").show();
	$(obj).next("input").focus();
}
function preUpdateDepartmentClass(obj){
	$(obj).children("span").hide();
	$(obj).children("input").show();
	$(obj).children("input").focus();
}
function update(obj) {
	// inspectionUpdateTestingClass

	var param = {
		id : $(obj).attr("dataid")
	};

	if ($(obj).attr("id") == "updateDepartmentName") {
		param.name = $(obj).val();
	}

	if ($(obj).attr("id") == "updateDepartmentClass") {
		param.departmentClass = $(obj).val();
	}
	if ($(obj).attr("id") == "updateImageName") {
		param.imageName = $(obj).val();
	}
	if ($(obj).attr("id") == "updateRank") {
		param.rank = $(obj).val();
		var regexp = /^[1-9]\d*$/;
	    if ( !( regexp.test($(obj).val() ) ) ) {
	    	alert("rank必须为数字");
	    	return;
	    }
	}

	API.sectionUpdateImage(param, function(res) {
		UTIL.releaseButton(obj);
		if (res.code == '0') {
			window.location.reload();
		} else {
			alert(res.desc);
			window.location.reload();
		}
	});
}

function upload(url, name,  rank, nameClass, obj) {

	
	$.ajaxFileUpload({
		url : url,
		secureuri : false,
		fileElementId : 'image',
		dataType : 'json',
		data : {
			"name" :name,
			"rank" : rank,
			"nameClass":nameClass
		},
		success : function(res) {
			if (res.code == '0') {
				alert("成功");
				window.location.href = "/section/section_image_list.htm?tabid=102_4";
			} else {
				alert(res.desc);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			if ($("#errorRequestStatus")) {
				$("#errorRequestStatus").val(XMLHttpRequest.status);
			}
			if ($("#errorRequestReadyState")) {
				$("#errorRequestReadyState").val(
						XMLHttpRequest.readyState);
			}
			if ($("#errorTextStatus")) {
				$("#errorTextStatus").val(textStatus);
			}
			// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
			if (XMLHttpRequest.status != 0) {
				alert('系统异常，请与管理员联系');
			}
		},
		complete : function() {
		}
	});
}


function batchAddClass() {
	$("#batchFile").click();
}

$("#batchFile").change(doBatchAdd);

function doBatchAdd() {
	var batchFile = $("#batchFile").val();
	var flag = "(.zip|.ZIP)$";
	 var re=new RegExp(flag);
	if (re.test(batchFile)) {
		$.ajaxFileUpload({
					url : "/section/batch_add_section_image.do",
					secureuri : false,
					fileElementId : 'batchFile',
					dataType : 'json',
					data : {},
					success : function(res) {
						if (res.code == '0') {
							alert("成功");
							window.location.href = "/section/section_image_list.htm?tabid=102_4";
						} else {
							alert(res.desc);
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						if ($("#errorRequestStatus")) {
							$("#errorRequestStatus").val(XMLHttpRequest.status);
						}
						if ($("#errorRequestReadyState")) {
							$("#errorRequestReadyState").val(
									XMLHttpRequest.readyState);
						}
						if ($("#errorTextStatus")) {
							$("#errorTextStatus").val(textStatus);
						}
						// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
						if (XMLHttpRequest.status != 0) {
							alert('系统异常，请与管理员联系');
						}
					},
					complete : function() {
					}
				});
	} else {
		window.location.href = "/section/section_image_list.htm?tabid=102_4";
		alert("文件格式必须为zip。");
	}
}


var typeFlag = 0 
function updateImage(id) {
	$("#id").val(id);
	$("#file").click();
}

$("#file").change(fileChange);

function fileChange() {
	var file = $("#file").val();
	var id = $("#id").val();
	if (/.*\.[png,PNG]/.test(file)) {
		$
				.ajaxFileUpload({
					url : "/section/update_section_image.do",
					secureuri : false,
					fileElementId : 'file',
					dataType : 'json',
					data : {
						"id" : id
					},
					success : function(res) {
						if (res.code == '0') {
							window.location.href = "/section/section_image_list.htm?tabid=102_4";
						} else {
							alert(res.desc);
							window.location.href = "/section/section_image_list.htm?tabid=102_4";
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						if ($("#errorRequestStatus")) {
							$("#errorRequestStatus").val(XMLHttpRequest.status);
						}
						if ($("#errorRequestReadyState")) {
							$("#errorRequestReadyState").val(
									XMLHttpRequest.readyState);
						}
						if ($("#errorTextStatus")) {
							$("#errorTextStatus").val(textStatus);
						}
						// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
						if (XMLHttpRequest.status != 0) {
							alert('系统异常，请与管理员联系');
						}
					},
					complete : function() {
					}
				});
	} else {
		alert("图片格式必须为PNG。");
	}
}


function updateDisable(id, obj) {
	var data = {
		"id" : id,
		disable : $(obj).val()
	};
	API.updateTestingClassDisable(data, function(res) {
		if (res.code == 0) {
			window.location.reload();
		} else {
			alert('系统异常，请与管理员联系');
		}
	});
}

function move(id, flag) {
	var data = {
		"id" : id,
		"flag" : flag
	};
	API.moveSectionImageRank(data, function(res) {
		if (res.code == 0) {
			window.location.reload();
		} else {
			alert(res.desc);
		}
	});
}

function deleteImage(id){
	var data = {
			"id" : id
		};
		API.sectionDeleteImage(data, function(res) {
			if (res.code == 0) {
				window.location.href = "/section/section_image_list.htm?tabid=102_4";
			} else {
				alert(res.desc);
			}
		});
}
function deleteWarn(id){
	var param = {
			id:id
		};
	API.sectionDeleteWarn(param,function(res) {
		if (res.code == '0') {
			location.reload();
		}else{
			alert(res.desc);
		}
	});
	
	
}
